
import { AK } from '@/assets/js/auth';

export default () => {
  const BMap_URL = "https://api.map.baidu.com/api?v=2.0&ak=" + AK + "&s=1&callback=onBMapCallback";
  return new Promise((resolve, reject) => {
    if (typeof BMap !== 'undefined') {
      resolve(BMap)
      return true
    }
    window.onBMapCallback = function () {
      console.log('百度地图初始化成功')
      resolve(BMap);
    }
    let script = document.createElement("script");
    script.setAttribute('type', 'text/javascript');
    script.setAttribute('src', BMap_URL);
    script.onerror = reject;
    document.body.appendChild(script);
  })
}
